package pl.edu.mimuw.irs.core.model.design.net;

import java.util.Map;

import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException;
import pl.edu.mimuw.irs.core.model.design.exception.InternalDesignException.DesignCause;
import pl.edu.mimuw.irs.core.model.design.resource.Requirements;

public class IRSRequirementCopier extends IRSPlaceCopier {

	// *** Attributes

	private IRSRequirement requirement;
	private int timeUnits;
	private Requirements requirements;
	public IRSRequirement getRequirement() {
		return requirement;
	}
	public int getTimeUnits() {
		return timeUnits;
	}
	public Requirements getRequirements() {
		return requirements;
	}
	
	// *** Constructors
	
	public IRSRequirementCopier(IRSRequirement requirement) {
		super(requirement);
		this.requirement = requirement;
		this.timeUnits = requirement.getTimeUnits();
		this.requirements = requirement.getRequirements();
	}
	
	// *** Methods
	
	protected IRSRequirement createPlainCopy(Map<IRSNode, IRSNode> clonesMap) {
		IRSRequirement clone = new IRSRequirement(getIdManager(), 
				getIdManager().getPrefixedNewId(getId()), getNodeType(), getPosition().clone(), 
				getTokens(), getTimeUnits(), getRequirements().copy());
		clone.setName(getName());
		return clone;
	}
	
	@Override
	public void copyAttributesTo(IRSNode target) {
		if (!(target instanceof IRSRequirement)) 
			throw new InternalDesignException(DesignCause.INCOMPATIBLE_COPY_NODES, getNode(), target);
		IRSRequirement targetRequirement = (IRSRequirement) target;
		targetRequirement.setTimeUnits(getTimeUnits());
		super.copyAttributesTo(target);
	}
}
